const { app, BrowserWindow, Menu, globalShortcut } = require('electron')

function createWindow(url) {
  const mainWindow = new BrowserWindow({
    width: 1280,
    height: 800,
    show: false,
  })
  mainWindow.loadURL(url)
  mainWindow.webContents.once('dom-ready', () => {
    mainWindow.show()
    mainWindow.maximize()
  })
  mainWindow.webContents.setWindowOpenHandler((data) => {
    createWindow(data.url)
    return {
      action: 'deny',
    }
  })
  mainWindow.on('focus', () => {
    globalShortcut.register('Ctrl+Shift+i', () => {
      mainWindow.webContents.openDevTools()
    })
    globalShortcut.register('F5', () => {
      mainWindow.reload()
    })
  })
  mainWindow.on('blur', () => {
    globalShortcut.unregisterAll()
  })
}
Menu.setApplicationMenu(null)
app.on('ready', () => {
  createWindow('http://qq362106048.gitee.io/vue2-poster/')
})
app.on('will-quit', () => {
  globalShortcut.unregisterAll()
})
app.on('window-all-closed', () => {
  app.quit()
})
